New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

local-machine-network

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-machine-network

Create a machine local network with leader election

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

local-machine-network

Provides a local machine network for simple inter-process communication (IPC).

Installation

npm install local-machine-network

Object based messaging

const { ObjectNetwork } = require('local-machine-network');

const net = new LowLevelNetwork({
  path: 'path-to-socket'
});

net.on('leader', () => {
  console.log('This instance is the leader!');
});

net.on('connection', other => {
  console.log('Incoming connection from someone else:', other);
});

net.on('message', { returnPath, data } => {
	console.log('Got a message:', data);

	if(data.type === 'request') {
		// If type is request send something back
		returnPath.send({
			type: 'response',
		});
	}
});

// Send a message to the leader - with any valid JSON
net.send({
	type: 'request',
});

Low-level networks

const { LowLevelNetwork } = require('local-machine-network');

const net = new LowLevelNetwork({
  path: 'path-to-socket'
});

net.on('leader', serverSocket => {
  console.log('This instance is the leader!');

  // Low-level networks requires the consumer to handle errors
  serverSocket.on('error', handleErrorProperly);
});

net.on('connected', socket => {
  console.log('Connected to the leader:', socket);

  // Low-level networks requires the consumer to handle errors
  socket.on('error', handleErrorProperly);
});

net.on('connection', socket => {
  console.log('Incoming connection from someone else:', socket);

  // Low-level networks requires the consumer to handle errors
  socket.on('error', handleErrorProperly);
});

Keywords

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc